package com.hrms.view;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.hrms.core.Constants;
import com.hrms.domain.Employee;
import com.hrms.domain.MyDashboard;

public class TeamDashboardView extends View{
	
	private String userId;
	private Employee viewingUser;
	private Boolean isTeam = Boolean.FALSE;
	
	public TeamDashboardView() {
		super();
	}
	
	public void service(HttpServletRequest req, HttpServletResponse res) {
		super.service(req, res);
	}

	@Override
	protected void persistEvents() {
		/*if(StringUtils.isNotEmpty(getUserAction())){
			
			
			
		}*/
	}
	
	public MyDashboard getRequestedDashboard(){
		return MyDashboard.getByUserId(userId);
	}
	
	public List<Employee> getTeamMembers(){
		return Employee.selectEmployeeByRole( viewingUser.getTeam());
	}


	@Override
	protected void initalize() {
		userId = getReqesutedUserId();
		
		if(!isSuper()){
			viewingUser = Employee.getByUserId(userId);
		}else{
			viewingUser = getAccessor();
		}
		
		checkForTeamUser();
	}

	public void checkForTeamUser(){
		if(getViewingUser()!=null){
			log(getViewingUser().getInitials());
			if(getViewingUser().getInitials().length() == Constants.TEAM_INTIALS_LIMIT){
				isTeam = Boolean.TRUE;
				addAsAParameter("userId", getViewingUser().getUserId());
			}
		}
	}
	
	public String getUserId() {
		return userId;
	}

	public Employee getViewingUser() {
		return viewingUser;
	}

	public Boolean isTeam() {
		return isTeam;
	}
	
	public String getViewingUserAlias(){
		
		if((getViewingUser()!=null) && (StringUtils.isNotBlank(getViewingUser().getUserId())) ){
			return StringUtils.substringBefore(getViewingUser().getUserId(), "@");
		}
		return null;
	}
	
}
